1 Dec, 2023
R is a programming language used by over 2 million people:
R and RStudio can be downloaded from: https://cran.r-project.org/


R is used programmatically, through typing commands and functions rather than clicking.
This means the main file is a list of instructions called a script, rather than a project file in ArcGIS.
Within a script, you can read in data, make changes and create plots/maps. But the scripts themselves are the most important thing.
Load required packages.
Import data (including shapefiles).
Pre-process data (clean, create new variables etc.).
Conduct analysis and modelling.
Create outputs, like maps and plots.
So, let’s give it a go.
Packages are useful add-ons to R that help with specific tasks. Here we load 3 packages:
dplyr: a package commonly used to aid data manipulation
sf: the main package for working with spatial data in R
ggplot2: a package to create nice looking plots (and maps)
The next stage is to import the data you’ll be using. Data should be saved in the same directory as the one you are working in with R.
Here we import two files:
a shapefile of all 2021 UK LSOA boundaries (using the st_read function)
a CSV of economic activity 2021 Census data for LSOAs in Manchester LA (using the read.csv function)
Like other GIS software, data needs to be joined to the shapefile using an ID column. We can do this in R using the inner_join function.
Here we create a new object called emp21_sf - this is just a name I’ve chosen. The arrow symbol (<-) gives an object a name.
We now need to calculate the economically inactive variable as a proportion of the total LSOA population. New variables like this can be created using the mutate function.
Any changes you make to data in R do not affect the original data - so you don’t need to worry too much about making mistakes!
Now we can plot the variable on a map.
There are a few ways to do this, but we use ggplot, one of the most common plotting functions in R.

More features: There are >20,000 packages currently available on CRAN.
It’s free! R is completely free and open source.
Can combine with other analysis: Easy to conduct non-spatial analysis on imported data.
Not as quick for simple mapping: For making quick and good-looking maps, R isn’t always the best.
Less immediate: There is a level of abstraction from the data you are using.
You need to know R: An initial learning curve that gets easier the more you use it.
These slides (made with Quarto in RStudio!) can be found on my Github: https://github.com/tmcunningham